package day5.compare;

/**
 * @author joker
 * @date 2022/4/16 0016 - 2:31
 */
public class Goods{
    private int price;
    private String name;

    public Goods() {
    }

    public Goods(int price, String name) {
        this.price = price;
        this.name = name;
    }

    public int getPrice() {
        return price;
    }

    @Override
    public String toString() {
        return "Goods{" +
                "price=" + price +
                ", name='" + name + '\'' +
                '}';
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

//    @Override
    public int compareTo(Object o) {
        if(o==null){
            throw new NullPointerException();
        }
        if(o instanceof Goods){
            Goods o1 = (Goods) o;
            if(this.price>o1.price){
                return 1;
            }else if(this.price<o1.price){
                return -1;
            }else {
                return this.name.compareTo(o1.name);
            }
        }
        throw new RuntimeException("数据不一致");
    }
}
